package com.zsummer.baikal.common.web;

import com.zsummer.baikal.common.constant.HttpStatus;
import io.swagger.annotations.ApiOperation;
import lombok.Data;

@Data
public class R<T> {

    private int code;

    private String msg;

    private T data;

    public static <T> R<T> ok() {
        return restResult(null, HttpStatus.SUCCESS, null);
    }

    public static <T> R<T> ok(T data) {
        return restResult(data, HttpStatus.SUCCESS, null);
    }

    public static <T> R<T> ok(T data, String msg) {
        return restResult(data, HttpStatus.SUCCESS, msg);
    }

    public static <T> R<T> failed() {
        return restResult(null, HttpStatus.ERROR, null);
    }

    public static <T> R<T> failed(String msg) {
        return restResult(null, HttpStatus.ERROR, msg);
    }

    public static <T> R<T> failed(T data) {
        return restResult(data, HttpStatus.ERROR, null);
    }

    public static <T> R<T> failed(T data, String msg) {
        return restResult(data, HttpStatus.ERROR, msg);
    }

    public static <T> R<T> restResult(T data, int code, String msg) {
        R<T> apiResult = new R<>();
        apiResult.setCode(code);
        apiResult.setData(data);
        apiResult.setMsg(msg);
        return apiResult;
    }
}
